import { Component, Inject } from 'vue-property-decorator';

import { mixins } from 'vue-class-component';
import JhiDataUtils from '@/shared/data/data-utils.service';

import { IRoomSearchGood } from '@/shared/model/room-search-good.model';
import RoomSearchGoodService from './room-search-good.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomSearchGoodDetails extends mixins(JhiDataUtils) {
  @Inject('roomSearchGoodService') private roomSearchGoodService: () => RoomSearchGoodService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomSearchGood: IRoomSearchGood = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomSearchGoodId) {
        vm.retrieveRoomSearchGood(to.params.roomSearchGoodId);
      }
    });
  }

  public retrieveRoomSearchGood(roomSearchGoodId) {
    this.roomSearchGoodService()
      .find(roomSearchGoodId)
      .then(res => {
        this.roomSearchGood = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
